package olSystem;

import com.spm.pojo.CourseForCjw;
import com.spm.utils.CFWMapperUtil;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.util.List;

/**
 * 主页显示信息的Servlet
 *
 * @author xxm
 *
 */
@WebServlet("/FindServlet")
public class FindServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public FindServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        //process(req, resp);
        doPost(req,resp);
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {

//        process(req, resp);
//        try {
//
//            // 创建Connection连接
//            DBOper dao = new DBOper();
//            Connection conn = dao.getConnection();
//            // SQL语句
////            String sql = "select * from course";
////            String sql1="select * from teacher_r_course";
////            String a="select Tid from teacher_r_course";
////            String sql2="select * from teacher where Tid = "+a;
//            String sql = "select * from course";
//            // 获取Statement
//            Statement statement =  conn.createStatement();
//
//            ResultSet resultSet = statement.executeQuery(sql);
//            ResultSet resultSet1 = statement.executeQuery(sql1);
//            ResultSet resultSet2= statement.executeQuery(sql2);
        CFWMapperUtil cfwMapperUtil = new CFWMapperUtil();
        List<CourseForCjw> courseList = cfwMapperUtil.selectAllCourseForCjw();
        for (CourseForCjw c: courseList
             ) {
            System.out.println(c);
        }
//            while (resultSet.next()) {
//                Course course = new Course();
//                course.setCourseId(resultSet.getInt("Cno"));
//                course.setCourseName(resultSet.getString("Cname"));
//                course.setCoursePlace(resultSet.getString("Cposition"));
//                course.setCourseRemain(resultSet.getInt("Capacity"));
//                course.setCourseTotal(resultSet.getInt("Csurplus"));
//                course.setCourseTeacher(resultSet.getString("Cteacher"));
//                course.setCourseTime(resultSet.getString("Cstarttime"));
//                course.setCourseTimelength(resultSet.getString("Clengthtime"));
//                courseList.add(course);
//            }
//            while (resultSet1.next()){
//                course.setCourseRemain(resultSet.getInt("Capacity"));
//                course.setCourseTotal(resultSet.getInt("Csurplus"));
//                courseList.add(course);
//            }
//            while (resultSet2.next()){
//                course.setCourseTeacher(resultSet.getString("Tname"));
//                courseList.add(course);
//            }
            req.setAttribute("courseList", courseList);
//
//            resultSet.close();
//            //resultSet1.close();
//            statement.close();
//            conn.close();
//
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
        resp.setCharacterEncoding("UTF-8");
        req.getRequestDispatcher("/Olsystem/select.jsp").forward(req, resp);
    }
    }


//    public void process(HttpServletRequest req, HttpServletResponse resp)
//            throws ServletException, IOException {
//        resp.setContentType("text/html;charset=utf-8");
//        req.setCharacterEncoding("UTF-8");
//
//
//}
